<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>

<html>
<head>
    <title>登录页</title>
    <%--echart线图、柱状图、饼图等各种图型库 cdn--%>
    <script type="text/javascript" src="https://cdn.jsdelivr.net/npm/echarts/dist/echarts.min.js"></script>
    <%--jquery cdn--%>
    <script type="text/javascript" src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.1/jquery.js"></script>
</head>
<body>

产品id <input name="productNum">

<input type="button" onclick="zxt()" value="点击展示折线图">
<input type="button" onclick="excel()" value="点击excel">
<%--渲染图表--%>
<div id="main" style="height: 500px;width: 800px" ></div>
</body>
<script>

function excel() {
    let productNum = $('[name=productNum]').val();
    window.location.href = 'excel.do?productNum=' + productNum
}

function zxt() {

    let productNum = $('[name=productNum]').val();

    $.ajax({
        url:'/zxt.do?productNum=' + productNum,

        success:function (data) {
            console.log(data)

            var xarray = [];
            var yarray = [];

            for (let i = 0; i < data.length; i++) {
                xarray.push(data[i].xdata);

                yarray.push(data[i].ydata);
            }
            var chartDom = document.getElementById('main');
            var myChart = echarts.init(chartDom);
            var option;

            option = {
                xAxis: {
                    type: 'category',
                    boundaryGap: false,
                    data: xarray
                },
                yAxis: {
                    type: 'value'
                },
                series: [
                    {
                        data: yarray,
                        type: 'line',
                        areaStyle: {}
                    }
                ]
            };

            option && myChart.setOption(option);



        }
    })

}







</script>
</html>